package com.sdy.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @program: ssm-sm
 * @author: sdy
 * @create: 2022-12-14 14:23
 **/
@WebFilter("/*")
public class CorsFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        //设置资源共享 允许跨域访问
         HttpServletResponse resp=(HttpServletResponse) servletResponse;
         resp.setHeader("Access-Control-Allow-Origin", "*");
//         resp.setHeader("Access-Control-Allow-Origin", "http://127.0.0.1:5500");
        //交给目标资源处理
        filterChain.doFilter(servletRequest, servletResponse);
    }

    @Override
    public void destroy() {

    }
}
